﻿// Decompiled with JetBrains decompiler
// Type: MCM.LightInject.GenericMappingResult
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;

#nullable disable
namespace MCM.LightInject
{
  [ExcludeFromCodeCoverage]
  internal class GenericMappingResult
  {
    private readonly string[] genericParameterNames;
    private readonly IDictionary<string, Type> genericArgumentMap;
    private readonly Type genericServiceType;
    private readonly Type openGenericImplementingType;

    internal GenericMappingResult(
      string[] genericParameterNames,
      IDictionary<string, Type> genericArgumentMap,
      Type genericServiceType,
      Type openGenericImplementingType)
    {
      this.genericParameterNames = genericParameterNames;
      this.genericArgumentMap = genericArgumentMap;
      this.genericServiceType = genericServiceType;
      this.openGenericImplementingType = openGenericImplementingType;
    }

    public bool IsValid
    {
      get
      {
        return (this.genericServiceType.GetTypeInfo().IsGenericType || !this.openGenericImplementingType.GetTypeInfo().ContainsGenericParameters) && ((IEnumerable<string>) this.genericParameterNames).All<string>((Func<string, bool>) (n => this.genericArgumentMap.ContainsKey(n)));
      }
    }

    public Type[] GetMappedArguments()
    {
      string[] array = ((IEnumerable<string>) this.genericParameterNames).Where<string>((Func<string, bool>) (n => !this.genericArgumentMap.ContainsKey(n))).ToArray<string>();
      if (((IEnumerable<string>) array).Any<string>())
        throw new InvalidOperationException("The generic parameter(s) " + ((IEnumerable<string>) array).Aggregate<string>((Func<string, string, string>) ((current, next) => current + "," + next)) + " found in type " + this.openGenericImplementingType.FullName + " cannot be mapped from " + this.genericServiceType.FullName);
      return ((IEnumerable<string>) this.genericParameterNames).Select<string, Type>((Func<string, Type>) (parameterName => this.genericArgumentMap[parameterName])).ToArray<Type>();
    }
  }
}
